/*
* Copyright (C) 2017-2018 Alibaba Group Holding Limited. All Rights Reserved.
*
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef ALIOS_SPEECH_FRONT_H_
#define ALIOS_SPEECH_FRONT_H_

#include <stdint.h>
#include <memory>
#include <string>

/**
* @file speech_front.h
* @brief This file contains FrontEngine public interface defined by AliOS,
* and is shared by the platform independent voice framework and the vendor specific Implementation.
***/

namespace alios {
class FrontEngineListener {
public:
    /** 请求成功 */
    static const int SUCCESS = 1000;
    /** 鉴权失败 */
    static const int ERROR_AUTH_FAIL = 1001;
    /** 音频处理失败 */
    static const int ERROR_AUDIO_FAILED = 1002;
public:
    virtual ~FrontEngineListener() {};
    /**
    * @brief 认证结果
    * @param vendor: 第三方引擎名称，status: 认证结果，true表示成功， false表示失败
    * @return
    */
    virtual void OnAuthResult(const std::string& vendor, bool status) = 0;
    /**
    * @brief 获取音频的回调函数
    * @param value 音频数据和数据长度
    * @return
    */
    virtual void OnVoiceData(int zone, const char* data, int length) = 0;
    /**
    * @brief 获取音频数据失败
    * @param value 错误码和错误提示
    * @return
    */
    virtual void OnError(int errorCode, const std::string& msg = "") = 0;
};

class FrontEngine {
public:
    FrontEngine() {}
    virtual ~FrontEngine() {}
    /**
    * @brief 初始化引擎
    * @param
    * @return
    */
    virtual int Initialize(const std::string &assets_path, const std::string &save_path) = 0;
    /**
    * @brief
    * @param
    * @return
    */
    virtual int Uninitialize() = 0;
    /**
    * @brief 设置回调函数
    * @param FrontEngineListener
    * @return
    */
    virtual void SetListener(FrontEngineListener* listener) = 0;
    /**
    * @brief 启动前端音频处理
    * @note
    * @param
    * @return 成功则返回0，否则返回-1
    */
    virtual int Start() = 0;
    /**
    * @brief 停止前端音频处理
    * @note
    * @param
    * @return 成功则返回0，否则返回-1
    */
    virtual int Stop() = 0;
    /**
    * @brief 取消前端音频处理
    * @note
    * @param
    * @return 成功则返回0，否则返回-1
    */
    virtual int Cancel() = 0;
    /**
    * @brief 送入音频数据
    * @note
    * @param
    * @return 成功则返回0，否则返回-1
    */
    virtual int Feed(char* data, int len) = 0;
    /**
    * @brief alios车机唯一机器码ID
    * @param[uuid] param uuid
    */
    virtual void SetUuid(const std::string &uuid) = 0;
    /**
    * @brief 获取引擎版本号
    * @return 引擎版本号
    */
    virtual const char *GetVersion() = 0;
    /**
    * @brief 引擎状态重置
    * @return 
    */
    virtual void Reset() = 0;
};

}  // namespace alios

#if __GNUC__ >= 4
#  define FRONT_ENGINE_EXPORT_API __attribute__ ((visibility ("default")))
#  define FRONT_ENGINE_IMPORT_API __attribute__ ((visibility ("default")))
#  define FRONT_ENGINE_INTERNAL   __attribute__ ((visibility ("hidden")))
#else
/** Visibility attribute to show method definitions */
#  define FRONT_ENGINE_EXPORT_API
/** Visibility attribute to show declarations */
#  define FRONT_ENGINE_IMPORT_API
/** Visibility attribute to hide declarations */
#  define FRONT_ENGINE_INTERNAL
#endif

#define FRONT_CREATEENGINE_SYM "Front_CreateEngine"
#define FRONT_DESTROYENGINE_SYM "Front_DestroyEngine"

/*----------------------------------------------------------------------*/
/*                        Function Prototypes                           */
/*----------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif

//
// Front Engine library default entry points.
// Front_CreateEngine/Front_DestroyEngine.
//

typedef alios::FrontEngine* (*Front_CreateEngineFunc)();
typedef void (*Front_DestroyEngineFunc)(alios::FrontEngine* engine);

#ifdef __cplusplus
}  /* end extern "C" */
#endif
#endif // ALIOS_SPEECH_FRONT_H_
